package com.xiaoxu.intranetweb.mybatisplusSzappdb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.entity.CAshGateVideoBind;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.entity.TAshgateHghtRecord;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.mapper.TAshgateHghtRecordMapper;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.service.ITAshgateHghtRecordService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lvNuo
 * @since 2025-02-21
 */
@Service
public class TAshgateHghtRecordServiceImpl extends ServiceImpl<TAshgateHghtRecordMapper, TAshgateHghtRecord> implements ITAshgateHghtRecordService {
    @Autowired
    private CAshGateVideoBindServiceImpl cAshGateVideoBindService;
    @Override
    //添加料位历史记录
    public void addMaterialLevelHistory() {
        QueryWrapper<CAshGateVideoBind> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("ASHGATE_DELETED",0);
//        有料位的装载点
        queryWrapper.eq("ASHGATE_TYPE",2);
//        有记录时间的数据
        queryWrapper.isNotNull("ASHGATE_ACQ_TM");
        List<CAshGateVideoBind> cAshGateVideoBindList =    cAshGateVideoBindService.list(queryWrapper);
        for (CAshGateVideoBind ashGateVideoBind : cAshGateVideoBindList) {
            TAshgateHghtRecord ashgateHghtRecord = baseMapper.newMaterialLevelHistory(ashGateVideoBind.getAshgateAcqTm(), ashGateVideoBind.getId());
            if (ashgateHghtRecord == null){
                TAshgateHghtRecord ashgateHghtRecord1 = new TAshgateHghtRecord();
                ashgateHghtRecord1.setReAshgateId(ashGateVideoBind.getId());
                ashgateHghtRecord1.setReAshgateName(ashGateVideoBind.getAshgateName());
                ashgateHghtRecord1.setReAshgateShrtname(ashGateVideoBind.getAshgateShrtname());
                ashgateHghtRecord1.setReAshgateCurHght(ashGateVideoBind.getAshgateCurHght());
                ashgateHghtRecord1.setReAshgateAcqTm(ashGateVideoBind.getAshgateAcqTm());
                ashgateHghtRecord1.setCreateTime(LocalDateTime.now());
                save(ashgateHghtRecord1);
            }
        }
    }
}
